fix: parentheses handling in CHECK constraint normalization#35
Merged
tianzhou merged 1 commit intopgplex:mainfrom Sep 23, 2025
Merged
fix: parentheses handling in CHECK constraint normalization#35tianzhou merged 1 commit intopgplex:mainfrom
tianzhou merged 1 commit intopgplex:mainfrom
Conversation
tianzhou
requested changes
Sep 23, 2025
Contributor
tianzhou
left a comment
There was a problem hiding this comment.
Thanks for the PR.
Let's add a separate create_table/add_check test case to verify this.
d533d19 to
6fa2fbb
Compare
Contributor
Author
|
@tianzhou check please |
Contributor
|
@grachevko Looks like the new test fails. Please check You can run PGSCHEMA_TEST_FILTER="create_table/add_check" go test -v ./internal/diff -run TestDiffFromFiles |
…tion - Add balanced parentheses validation before removing outer parentheses - Prevent incorrect normalization of complex expressions with nested parentheses - Improve robustness of CHECK constraint parsing logic
Contributor
Author
➜ pgschema git:(main) ✗ PGSCHEMA_TEST_FILTER="create_table/add_check" go test -v ./internal/diff -run TestDiffFromFiles
=== RUN TestDiffFromFiles
=== RUN TestDiffFromFiles/create_table_add_check
--- PASS: TestDiffFromFiles (0.01s)
--- PASS: TestDiffFromFiles/create_table_add_check (0.01s)
PASS
ok github.com/pgschema/pgschema/internal/diff 0.020s |
tianzhou
approved these changes
Sep 23, 2025
Contributor
tianzhou
left a comment
There was a problem hiding this comment.
LGTM. Thanks for the fix!
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR fixes a critical issue in the CHECK constraint normalization logic where improperly balanced parentheses could lead to incorrect expression parsing.
Problem Fixed
The previous implementation would remove ALL outer parentheses without checking if they were properly balanced or part of a larger expression structure.
This break expressions like:
CHECK ((code >= 0) AND (code <= 255))Previous:
CHECK (code >= 0) AND (code <= 255)Current:
CHECK (code >= 0 AND code <= 255)